package com.jeomo.mem.starter.mapper;

import com.jeomo.base.starter.mapper.IBaseMapper;
import com.jeomo.mem.starter.entity.MemberPointsActivityExe;
import com.jeomo.mem.starter.entity.MemberPointsActivityRule;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * 会员积分活动规则
 *
 * @author:Jackpot
 * @create 2020-09-28 16:42
 * @description:
 */
@Mapper
public interface MemberPointsActivityRuleMapper extends IBaseMapper<MemberPointsActivityRule> {

    @Select("select m.id,m.code,m.name from member_points_activity_rule as m where m.code=#{code}")
    MemberPointsActivityRule queryById(String code);

    /**
     * 获取符合条件的会员积分规则
     * @param date  时间
     * @param level 会员等级
     * @param price 消费金额
     * @return
     */
    @Select(" select m.code as rule_code,t.name as activity_name,t.multi_ratio,t.add_ratio,d.bs_code,d.permit" +
            " from member_points_activity_rule as m join member_points_activity_rule_list as d on m.code=d.rule_code" +
            " join member_points_activity as t on t.code=m.activity_code "+
            " where m.date_from <= #{date} and m.date_to >= #{date} " +
            " and LOCATE(#{level},m.use_levels)>0 and m.price_floor <= #{price} and m.price_ceiling >= #{price} " +
            " and m.start_flag=1")
    List<MemberPointsActivityExe> getAllActivitiesByCond(Date date, String level, Double price);
}
